#include <algorithm>
#include <iostream>
using namespace std;

const int kInf = 1e9;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  int ans = -kInf, min_pre = 0, sum = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    ans = max(ans, sum - min_pre);
    min_pre = min(min_pre, sum);
  }
  cout << ans << "\n";
  return 0;
}